// 按需引入方式
import echarts from "@/views/package/echarts/components/BaseEcharts/utils/echarts";

export function getOptions(requestData) {
  console.log("requestData", requestData);
  // const unitList = [, '2F', '3F', '4F', '5F'];
  const originData = {
    待定次数: [
      ["1F", 1000],
      ["2F", 2000],
      ["3F", 3000],
      ["4F", 4000],
      ["5F", 5000],
    ],
    开机次数: [
      ["1F", 500],
      ["2F", 600],
      ["3F", 700],
      ["4F", 800],
      ["5F", 900],
    ],
    停机次数: [
      ["1F", 1100],
      ["2F", 1200],
      ["3F", 1300],
      ["4F", 1400],
      ["5F", 1500],
    ],
    lineData: [
      ["1F", 1200],
      ["2F", 12200],
      ["3F", 13300],
      ["4F", 14400],
      ["5F", 15050],
    ],
  };

  originData["待定次数top"] = originData["待定次数"].map((item, index) => {
    const value = item[1];
    return [item[0], value];
  });
  originData["开机次数top"] = originData["开机次数"].map((item, index) => {
    const value = item[1] + originData["待定次数"][index][1];
    return [item[0], value];
  });

  originData["停机次数top"] = originData["停机次数"].map((item, index) => {
    const value =
      item[1] +
      originData["待定次数"][index][1] +
      originData["开机次数"][index][1];
    return [item[0], value];
  });

  const option = {
    legend: {
      show: true,
      selectedMode: false,
    },
    tooltip: {
      show: true,
    },
    yAxis: [
      {
        show: true,
        name: "点数（次）",
        position: "right",
      },
      {
        name: "合格率（%）",
        position: "left",
        show: true,
      },
    ],
    xAxis: {
      type: "category",
      triggerEvent: true,
      axisPointer: {
        show: true,
        type: "shadow",
      },
      show: true,
      axisLabel: {
        color: "#6E7078",
      },
    },
    series: [
      // 待定次数  柱状体   datasetIndex: 0,
      {
        name: "待定次数",
        yAxisIndex: 0,
        barWidth: 20,
        encode: {
          x: "机组序号",
          y: "开机次数",
        },
        datasetIndex: 0,
        type: "bar",
        z: 0,
        symbol: "diamond",
        label: {
          borderWidth: 0,
          borderRadius: 4,
        },
        markPoint: {
          label: {
            borderWidth: 0,
            borderRadius: 4,
          },
        },
        markLine: {
          label: {
            borderWidth: 0,
            borderRadius: 4,
          },
        },
        markArea: {
          label: {
            borderWidth: 0,
            borderRadius: 4,
          },
        },
        stack: "0",
        barGap: "30%",
        itemStyle: {
          color: {
            x: 0,
            y: 0,
            x2: 0,
            y2: 1,
            type: "linear",
            global: false,
            colorStops: [
              {
                offset: 0,
                color: "rgb(0,72,146)",
              },
              {
                offset: 1,
                color: "rgba(0,72,146,0.3)",
              },
            ],
          },
          color: "red",
        },
      },
      // 待定次数 顶盖   。datasetIndex: 1,
      {
        name: "开机次数",
        datasetIndex: 1,
        yAxisIndex: 0,
        barWidth: 20,
        type: "pictorialBar",
        symbol: "diamond",
        symbolPosition: "end",
        symbolSize: [20, 7],
        symbolOffset: ["0%", "-50%"],
        z: 1,
        tooltip: {
          show: false,
        },
        label: {
          borderWidth: 0,
          borderRadius: 4,
        },
        markPoint: {
          label: {
            borderWidth: 0,
            borderRadius: 4,
          },
        },
        markLine: {
          label: {
            borderWidth: 0,
            borderRadius: 4,
          },
        },
        markArea: {
          label: {
            borderWidth: 0,
            borderRadius: 4,
          },
        },
        barGap: "-100%",
        itemStyle: {
          color: "#3870aa",
          // color: 'yellow'
        },

        encode: {
          x: "name",
          y: "value",
        },
      },
      // 开机次数 柱状体   datasetIndex: 2,
      {
        name: "开机次数",
        datasetIndex: 2,
        yAxisIndex: 0,
        barWidth: 20,
        encode: {
          x: "机组序号",
          y: "开机次数",
        },

        type: "bar",
        z: 0,
        symbol: "diamond",
        label: {
          borderWidth: 0,
          borderRadius: 4,
        },
        markPoint: {
          label: {
            borderWidth: 0,
            borderRadius: 4,
          },
        },
        markLine: {
          label: {
            borderWidth: 0,
            borderRadius: 4,
          },
        },
        markArea: {
          label: {
            borderWidth: 0,
            borderRadius: 4,
          },
        },
        stack: "0",
        barGap: "30%",
        itemStyle: {
          color: {
            x: 0,
            y: 0,
            x2: 0,
            y2: 1,
            type: "linear",
            global: false,
            colorStops: [
              {
                offset: 0,
                color: "rgb(0,72,146)",
              },
              {
                offset: 1,
                color: "rgba(0,72,146,0.3)",
              },
            ],
          },
        },
      },
      // 开机次数 顶盖      datasetIndex: 3,
      {
        name: "开机次数",
        datasetIndex: 3,
        yAxisIndex: 0,
        barWidth: 20,
        type: "pictorialBar",
        symbol: "diamond",
        symbolPosition: "end",
        symbolSize: [20, 7],
        symbolOffset: ["0%", "-50%"],
        z: 1,
        tooltip: {
          show: false,
        },
        label: {
          borderWidth: 0,
          borderRadius: 4,
        },
        markPoint: {
          label: {
            borderWidth: 0,
            borderRadius: 4,
          },
        },
        markLine: {
          label: {
            borderWidth: 0,
            borderRadius: 4,
          },
        },
        markArea: {
          label: {
            borderWidth: 0,
            borderRadius: 4,
          },
        },
        barGap: "-100%",
        itemStyle: {
          color: "#3870aa",
          color: "yellow",
        },

        encode: {
          x: "name",
          y: "value",
        },
      },
      // 停机次数 柱状体    datasetIndex: 4,
      {
        name: "停机次数",
        datasetIndex: 4,
        yAxisIndex: 0,
        barWidth: 20,
        encode: {
          x: "机组序号",
          y: "停机次数",
        },
        type: "bar",
        z: 0,
        symbol: "diamond",
        label: {
          borderWidth: 0,
          borderRadius: 4,
        },
        markPoint: {
          label: {
            borderWidth: 0,
            borderRadius: 4,
          },
        },
        markLine: {
          label: {
            borderWidth: 0,
            borderRadius: 4,
          },
        },
        markArea: {
          label: {
            borderWidth: 0,
            borderRadius: 4,
          },
        },
        stack: "0",
        barGap: "30%",
        itemStyle: {
          color: {
            x: 0,
            y: 0,
            x2: 0,
            y2: 1,
            type: "linear",
            global: false,
            colorStops: [
              {
                offset: 0,
                color: "rgb(40,169,134)",
              },
              {
                offset: 1,
                color: "rgba(40,169,134,0.3)",
              },
            ],
          },
        },
      },
      // 停机次数 顶盖     datasetIndex: 5,
      {
        name: "停机次数",
        yAxisIndex: 0,
        barWidth: 20,
        type: "pictorialBar",
        symbol: "diamond",
        symbolPosition: "end",
        datasetIndex: 5,
        symbolSize: [20, 7],
        symbolOffset: ["0%", "-50%"],
        z: 1,
        tooltip: {
          show: false,
        },
        label: {
          borderWidth: 0,
          borderRadius: 4,
        },
        markPoint: {
          label: {
            borderWidth: 0,
            borderRadius: 4,
          },
        },
        markLine: {
          label: {
            borderWidth: 0,
            borderRadius: 4,
          },
        },
        markArea: {
          label: {
            borderWidth: 0,
            borderRadius: 4,
          },
        },
        barGap: "-100%",
        itemStyle: {
          color: "#57bca1",
        },
        encode: {
          x: "name",
          y: "value",
        },
      },
      // 停机次数 底盖     datasetIndex: 6,
      // {
      //   name: '停机次数',
      //   yAxisIndex: 0,
      //   barWidth: 20,
      //   type: 'pictorialBar',
      //   symbol: 'diamond',
      //   symbolPosition: 'start',
      //   datasetIndex: 5,
      //   symbolSize: [20, 7],
      //   symbolOffset: ['0%', '-50%'],
      //   z: 1,
      //   tooltip: {
      //     show: false
      //   },
      //   label: {
      //     borderWidth: 0,
      //     borderRadius: 4
      //   },
      //   markPoint: {
      //     label: {
      //       borderWidth: 0,
      //       borderRadius: 4
      //     }
      //   },
      //   markLine: {
      //     label: {
      //       borderWidth: 0,
      //       borderRadius: 4
      //     }
      //   },
      //   markArea: {
      //     label: {
      //       borderWidth: 0,
      //       borderRadius: 4
      //     }
      //   },
      //   barGap: '-100%',
      //   itemStyle: {
      //     color: '#57bca1'
      //   },
      //   encode: {
      //     x: 'name',
      //     y: 'value'
      //   }
      // },
      // 折线  datasetIndex: 7,
      {
        datasetIndex: 7,
        yAxisIndex: 1,
        itemStyle: {
          color: "red",
        },
        type: "line",
        smooth: false,
      },
    ],
    dataset: [
      // 待定次数  柱状体   datasetIndex: 0,
      {
        dimensions: ["机组序号"],
        source: originData["待定次数"],
      },
      // 待定次数 顶盖   。datasetIndex: 1,
      {
        dimensions: ["name", "value"],
        source: originData["待定次数top"],
      },
      // 开机次数 柱状体   datasetIndex: 2,
      {
        dimensions: ["name", "value"],
        source: originData["开机次数"],
      },
      // 开机次数 顶盖      datasetIndex: 3,
      {
        dimensions: ["name", "value"],
        source: originData["开机次数top"],
      },
      // 停机次数 柱状体    datasetIndex: 4,
      {
        dimensions: ["name", "value"],
        source: originData["停机次数"],
      },
      // 停机次数 顶盖     datasetIndex: 5,
      {
        dimensions: ["name", "value"],
        source: originData["停机次数top"],
      },
      // 停机次数 低盖     datasetIndex: 6,
      {
        dimensions: ["name", "value"],
        source: originData["停机次数top"],
      },

      // 折线  datasetIndex: 7,
      {
        dimensions: ["name", "合格率"],
        source: originData["lineData"],
      },
    ],
  };

  return option;
}
